/** 
 *  @file
 *  @brief   槽（C）形2（CHAN2）梁截面属性使用解析公式计算类
 *  @author  xiaochangjiang
 *  @date    2024.04.05
 *  @version v1.0
 *  @par Copyright(c):  ShenGong  Simulation corporation
 */

#include "Chan2SectionFormulaCalculator.h"
#include "DataStructure/Common/Real.h"

using SG::DataStructure::Common::Real;
using SG::DataStructure::FEM::PBARLData;
using SG::DataStructure::FEM::PBARData;
using SG::FEMSolver::Element::Chan2SectionFormulaCalculator;

void Chan2SectionFormulaCalculator::Compute
(
const SG::DataStructure::FEM::PBARLData& section,
_OUT SG::DataStructure::FEM::PBARData&   property,
_OUT SG::Algebra::Point&                 centroid
) const
{
    Real tw{section.m_dimension[1]};
    Real tf{section.m_dimension[0]};
    Real b{section.m_dimension[2] - 0.5 * tw};
    Real h{section.m_dimension[3] - tf};
    Real bf{section.m_dimension[2] - tw};
    Real hw{section.m_dimension[3] - 2.0 * tf};

    property.m_id  = section.m_id;
    property.m_mId = section.m_mId;
    property.m_A   = 2.0 * tf * bf + (h + tf) * tw;
    // Real yS = -b * b * tf / (2.0 * b * tf + h * tw / 3.0);
    // Real zS = 0.0;
    Real yC = bf * tf * (bf + tw) / property.m_A;
    // Real yC = 0.0;
    property.m_I1  = (h + tf) * tw * tw * tw / 12.0 + tf * bf * bf * bf / 6.0 + tf * bf * (bf + tw) * (bf + tw) * 0.5 -
                     property.m_A * yC * yC;
    property.m_I2  = tw * (h + tf) * (h + tf) * (h + tf) / 12.0 + bf * tf * tf * tf / 6.0 + bf * tf * h * h * 0.5;
    property.m_I12 = 0.0;
    property.m_J   = (2.0 * b * tf * tf * tf + h * tw * tw * tw) / 3.0;
    property.m_K1  = 2.0 * tf * bf / property.m_A;
    property.m_K2  = tw * hw / property.m_A;
    property.m_NSM = section.m_nsm;
    property.m_FE  = 0.0;
    property.SetStressPoints ({-yC + b,         0.5 * (h + tf),
                               -yC - 0.5 * tw,  0.5 * (h + tf),
                               -yC - 0.5 * tw, -0.5 * (h + tf),
                               -yC + b,        -0.5 * (h + tf)});
    centroid.m_x = 0.0;
    centroid.m_y = 0.0;
    centroid.m_z = 0.0;
}